package metamodels;

import parser.generic.Node;
import utils.Utils;


public class Metamodel extends Node implements K{
	
	ProperMetamodel metamodel;
	Constraints constraints;
	
	public Metamodel(ProperMetamodel properMetamodel) {
		this(properMetamodel, null);
	}

	public Metamodel(ProperMetamodel properMetamodel, Constraints constraints) {
		metamodel = properMetamodel;
		this.constraints = constraints;
	}

	@Override
	public String toString() {
		return metamodel + "\n" + constraints;
	}

	@Override
	public String toK() {
		
		String out = "";
		
		out += "require " + Utils.OCL + "\n\n";
		out += "module META-MODEL is including K + OCL-SEMANTICS\n\n";
		out += "syntax K ::= #Id\n\n";
		out += "syntax #Id ::= " + metamodel.getIdentifiers() + "\n\n";
		out += "syntax Bag ::= children ( #Id )\n\n";
		
		out += metamodel.getInheritanceRules() + "\n\n";
	
		out += "syntax Map ::= attributeDecl ( #Id ) \n\n";
		
		out += metamodel.getAttributeDeclRules() + "\n\n";
		
		out += "syntax #Bool ::= isEnum ( #Id )\n\n";
		
		out += metamodel.getEnumRules()  + "\n\n";
		
		out += "syntax Bag ::= values ( #Id )\n\n";
		out += metamodel.getEnumValuesRule() + "\n\n";
		
		out += "end module";
		return out;
	}

	public String getConstraints() {
		return constraints.toK();
	}
}
